package com.main.ok.guahaouser;

import com.caucho.hessian.client.HessianConnection;
import com.caucho.hessian.client.HessianProxy;
import com.caucho.hessian.client.HessianProxyFactory;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by kai on 2015/8/11 0011.
 * 给hessina添加http报文头
 */
public class HessianProxyWithContext extends HessianProxy {
    private Map<String, String> context = new HashMap<String, String>();

    protected HessianProxyWithContext(URL url, HessianProxyFactory factory) {
        super(url, factory);
    }

    public Map<String, String> getContext() {
        return context;
    }

    public void setContext(Map<String, String> context) {
        this.context = context;
    }

    protected HessianProxyWithContext(URL url, HessianProxyFactory factory, Class<?> type) {
        super(url, factory, type);
    }

    @Override
    protected void addRequestHeaders(HessianConnection conn) {
        super.addRequestHeaders(conn);
        for (Map.Entry<String, String> entry : context.entrySet()) {
            conn.addHeader(entry.getKey(), entry.getValue());
        }
    }
}
